/////////////////////////////////////////////////////
// File Name: queue_manager_tb.v
// Author: zeping fan
// mail:   zpfan007@163.com
// Created Time: 2023年06月28日 星期三 14时51分57秒
/////////////////////////////////////////////////////

module queue_manager_tb();

reg                 clk;
reg                 rst_n;

reg                 sof;
reg                 dv;
reg     [7:0]       din;

reg     [3:0]       ptr_fifo_rd;
reg     [3:0][15:0] ptr_fifo_dout;
wire    [3:0]       ptr_fifo_empty;
reg     [3:0]       data_fifo_rd;
reg     [3:0][7:0]  data_fifo_dout;


always #5   clk = ~clk;

initial begin
    $fsdbDumpfile("queue_manager.fsdb");
    $fsdbDumpvars(0,queue_manager_tb);
    $fsdbDumpMDA();

    clk = 1'b0;
    rst_n = 1'b0;
    sof = 1'b0;
    dv  = 1'b0;
    din[7:0] = 8'b0;
    ptr_fifo_rd[3:0]= 4'b0;
    data_fifo_rd[3:0] = 4'b0; 

    repeat(2)@(posedge clk);#0;
    rst_n = 1'b1;
    repeat(5)@(posedge clk);#0;
    write(
        4'b0010,
        12'd60,
        48'hf0f1f2f3f4f5,
        48'he0e1e2e3e4e5,
        16'h0800
    );
     #1000;

    write(
        4'b1000,
        12'd54,
        48'ha0a1a2a3a4a5,
        48'hb0b1b2b3b4b5,
        16'h0806
    );
     #1000;

    write(
        4'b1011,
        12'd80,
        48'hc0c1c2c3c4c5,
        48'hd0d1d2d3d4d5,
        16'h8808
    );
    #1500;
    $finish;
end



task    write();
    input   [3:0]   port_id;
    input   [11:0]  length;
    input   [47:0]  de_addr;
    input   [47:0]  so_addr;
    input   [15:0]  frame_type;
begin
    sof = 1'b1;
    dv = 1'b1;
    din[7:0] = {length[11:8],port_id};
    @(posedge clk);#0;
    sof = 1'b0;
    din[7:0] = length[7:0];
    @(posedge clk);#0;
    for(integer i=14;i>0;i=i-1)begin
        if(i>8)
            din[7:0] = de_addr[8*(i-8)-1-:8];
        else if(i>2)
            din[7:0] = so_addr[8*(i-2)-1-:8];
        else 
            din[7:0] = frame_type[8*i-1-:8];
        @(posedge clk);#0;
    end
    for(integer j=0;j<length-16;j=j+1)begin
        din[7:0] = j;
        @(posedge clk);#0;
    end
    dv = 1'b0;
end
endtask




queue_manager_v1#(
    .PORT_NUM(4)
)
queue_manager(
.clk(clk),
.rst_n(rst_n),

.sof(sof),
.dat_vld(dv),
.din(din),
.bp(),

.ptr_fifo_rd(ptr_fifo_rd),
.ptr_fifo_dout(ptr_fifo_dout),
.ptr_fifo_empty(ptr_fifo_empty),
.data_fifo_rd(data_fifo_rd),
.data_fifo_dout(data_fifo_dout)
);

endmodule
